<template>

  <el-drawer :with-header="false" :visible.sync="open_order" size="50%" direction="rtl" :show-close="false"
    :wrapperClosable="false" @closed='closed' @opened="opened">
    <el-row :gutter="20" class="mt20">
      <el-col :span="12">
        <div class="ml30 ">
          <div class="grid-content bg-purple-dark    text-size-20  " style="font-weight: 700;">报名续课</div>



        </div>

      </el-col>
      <el-col :span="12">
        <div class="classflex-end">

          <el-button @click="cancel" style="width: 100px;margin-right: 100px;">取消</el-button>

        </div>

      </el-col>
    </el-row>
    <el-divider></el-divider>
    <div class="ml20 classflex-left mb20">
      <div class="grid-content bg-purple-dark    text-size-17  ">基本信息</div>
      <div class="  text-gray  text-size-17 ml20 ">实际报名日期，多次报名同课程将优先消耗先经办的订单</div>


    </div>
    <!-- {{queryParamsStudent}} -->
    <!-- {{form}} -->
    <el-form :hide-required-asterisk="true" ref="form" :model="form" :rules="rules_order" label-width="80px"
      label-position="top">
      <div class="ml20 mr20">
        <el-row :gutter="30">
          <el-col :span="8">
            <div class="">
              <el-form-item label="报名学员" prop="orderStudentName">
                <el-select style="width: 80%;" v-model="form.orderStudentName" placeholder="请选择报名学员" filterable
                  @change="getstudentmessage">
                  <el-option v-for="dict in studentList" :key="dict.id" :label="dict.userName" :value="dict.userName">
                  </el-option>

                </el-select>
              </el-form-item>
            </div>

          </el-col>
          <el-col :span="8">
            <div class="ml20">

              <el-form-item label="报名课程" prop="orderCourse">

                <el-select style="width: 80%;" v-model="form.orderCourse" placeholder="请选择报名课程" filterable>
                  <el-option v-for="dict in courseList" :key="dict.id" :label="dict.courseName"
                    :value="dict.courseName">
                  </el-option>

                </el-select>


              </el-form-item>
            </div>

          </el-col>
          <el-col :span="8">
            <div class="ml20">
              <el-form-item label="经办日期" prop="orderTime">

                <el-date-picker @input="$forceUpdate()" @change="handleChange(1)" v-model="form.orderTime" type="date"
                  style="width: 80%;" placeholder="选择日期" value-format="yyyy-MM-dd" :picker-options="pickerOptions">
                </el-date-picker>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
      </div>
      <div class="classflex-left ml20 mb20">
        <div>报名信息</div>
        <div class="ml20">
          <el-radio-group v-model="form.orderType">
            <el-radio-button label="按课时"></el-radio-button>
            <el-radio-button label="按时段"></el-radio-button>

          </el-radio-group>
        </div>
      </div>
      <!-- {{form.orderType}} -->
      <div v-if="form.orderType=='按课时'">
        <div class="ml20 mr20">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="购买课时数" prop="orderCourseNumber">

                <el-input-number @change="handlemoneyChange(1)" v-model="form.orderCourseNumber" :min="0" :max="1000"
                  style="margin-left: 5px; width: 80%;" label="描述文字" controls-position="right"></el-input-number>
                <!-- <el-input v-model="form.orderCourseNumber" placeholder="请输入购买课时数" /> -->
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="赠送课时数" prop="orderFreecourseNumber">
                <el-input-number @change="handlemoneyChange(2)" style="margin-left: 5px; width: 80%;"
                  v-model="form.orderFreecourseNumber" :min="0" :max="100" label="描述文字" controls-position="right">
                </el-input-number>
                <!-- <el-input v-model="form.orderFreecourseNumber" placeholder="请输入赠送课时数" /> -->
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="设置有效期 0天表示长期有效" prop="day">

                <el-input-number @input="$forceUpdate()" @change="handleChange(2)"
                  style="margin-left: 5px;  width: 80%;" v-model="day" :min="0" :max="1000" label="描述文字"
                  controls-position="right">
                </el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="到期日" prop="orderCourseEndtime">
                <!-- {{form.orderCourseEndtime}} -->
                <el-date-picker @input="$forceUpdate()" @change="handleChange(3)" v-model="form.orderCourseEndtime"
                  type="date" style="margin-left: 5px;  width: 80%;" placeholder="选择日期" format="yyyy-MM-dd">
                </el-date-picker>


              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </div>
      <div v-if="form.orderType=='按时段'">
        <div class="ml20 mr20">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="设置有效期 0天表示长期有效" prop="day">

                <el-input-number @input="$forceUpdate()" @change="handleChange(2)"
                  style="margin-left: 5px;  width: 80%;" v-model="day" :min="0" :max="1000" label="描述文字">
                </el-input-number>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="到期日" prop="orderCourseEndtime">
                <el-date-picker @input="$forceUpdate()" @change="handleChange(3)" v-model="form.orderCourseEndtime"
                  type="date" style="margin-left: 5px;  width: 80%;" placeholder="选择日期" value-format="yyyy-MM-dd">
                </el-date-picker>


              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </div>



      <!-- {{tableDataOrderother}}
      {{tableDataSale}} -->
      <div class="ml20 mr20">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="应收金额(元)" prop="amountReceivable">
              <el-input v-model="form.amountReceivable" prefix-icon="el-icon-edit" placeholder="请输入应收金额"
                style="margin-left: 5px; width: 80%;" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="优惠金额(元)" prop="discountAmount">
              <el-input v-model="form.discountAmount" prefix-icon="el-icon-edit" placeholder="请输入优惠金额"
                style="margin-left: 5px; width: 80%;" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="实收金额(元)" prop="actualAmountReceived">
              <el-input @change="handlemoneyChange(2)" v-model="form.actualAmountReceived" prefix-icon="el-icon-edit"
                style="margin-left: 5px; width: 80%;" placeholder="请输入实收金额" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="form.orderType=='按课时'">
            <el-form-item label="单价(每节课)" prop="unitPrice">
              <el-input v-model="form.unitPrice" prefix-icon="el-icon-edit" placeholder="" disabled
                style="margin-left: 5px; width: 80%;" />
            </el-form-item>
          </el-col>
          <el-col :span="6" v-else>
            <el-form-item label="单价(每天)" prop="unitPrice">
              <el-input v-model="form.unitPrice" prefix-icon="el-icon-edit" placeholder="" disabled
                style="margin-left: 5px; width: 80%;" />
            </el-form-item>
          </el-col>
        </el-row>
      </div>

      <div class="app-container">
        <div class="ml20 classflex-space-between mb20">
          <div class="grid-content bg-purple-dark    text-size-17  ">其他收费项</div>
          <!-- 添加一行数据 -->
          <el-button type="primary" class="buttonAdd" icon="el-icon-plus" @click="addRow(1)">添加收费项</el-button>


        </div> <!-- 表格 -->
        <el-table :data="tableDataOrderother" border>
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column prop="ID" label="收费项">
            <template slot-scope="scope">

              <el-select v-model="scope.row.orderother" placeholder="请选择收费项" filterable>
                <el-option v-for="dict in expenditureList" :key="dict.id" :label="dict.expenditureName"
                  :value="dict.expenditureName">
                </el-option>

              </el-select>

            </template>
          </el-table-column>
          <el-table-column prop="orderothernumber" label="数量">
            <template slot-scope="scope">
              <el-input-number style="margin-left: 5px;" v-model="scope.row.orderothernumber" :min="1" :max="10"
                label="描述文字"></el-input-number>
            </template>
          </el-table-column>
          <el-table-column prop="oaUserIds" label="金额">
            <template slot-scope="scope">

              <el-input v-model="scope.row.orderothermoney"></el-input>
            </template>
          </el-table-column>

          <el-table-column label="操作"> <template slot-scope="scope">

              <div class="classflex-center">
                <el-button icon="el-icon-delete" @click="deleteRow(1,scope.row)">删除</el-button>
              </div>



            </template>
          </el-table-column>
        </el-table>


      </div>

      <div class="app-container">
        <div class="ml20 classflex-space-between mb20">
          <div class="grid-content bg-purple-dark    text-size-17  ">销售业绩分配</div> <!-- 添加一行数据 -->
          <el-button type="primary" class="buttonAdd" icon="el-icon-plus" @click="addRow(2)">添加业绩分配</el-button>


        </div> <!-- 表格 -->
        <el-table :data="tableDataSale" border>
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column prop="Id" label="销售人员">
            <template slot-scope="scope">



              <el-select v-model="scope.row.user" placeholder="请选择销售人员" filterable>
                <el-option v-for="dict in userList" :key="dict.userId" :label="dict.nickName" :value="dict.nickName">
                </el-option>

              </el-select>


            </template>
          </el-table-column>
          <el-table-column prop="postId" label="业绩比例(百分比)">
            <template slot-scope="scope">
              <el-input-number style="margin-left: 5px;" v-model="scope.row.usernumber" :min="1" :max="100" label="描述文字"
                controls-position="right">
              </el-input-number>
            </template>
          </el-table-column>


          <el-table-column label="操作">
            <template slot-scope="scope">

              <div class="classflex-center">
                <el-button icon="el-icon-delete" @click="deleteRow(2,scope.row)">删除</el-button>
              </div>



            </template>
          </el-table-column>
        </el-table>


      </div>

      <div class="ml20 mr20">
        <el-form-item label="备注" prop="orderRemark">
          <el-input v-model="form.orderRemark" placeholder="请输入备注" />
        </el-form-item>
      </div>
    </el-form>
    <el-divider></el-divider>
    <div class="ml20 mr20">
      <el-button type="primary" @click="submitForm" style="width: 100%;">立即报名</el-button>

    </div>
  </el-drawer>

</template>

<script>
  import {
    calculateDaysAfter,
    calculateDaysBetween
  } from "@/utils/ruoyi";
  import {
    listOrder,
    getOrder,
    delOrder,
    addOrder,
    updateOrder
  } from "@/api/order/order";
  import {
    listUser,
    listUser2,
    getUser,
    delUser,
    addUser,
    updateUser,
    resetUserPwd,
    changeUserStatus,
    deptTreeSelect
  } from "@/api/system/user";
  import {
    listStudent,
    getStudent,
    delStudent,
    addStudent,
    updateStudent
  } from "@/api/student/student";
  import {
    listCourse,
    getCourse,
    delCourse,
    addCourse,
    updateCourse
  } from "@/api/course/course";
  import {
    listExpenditure,
    getExpenditure,
    delExpenditure,
    addExpenditure,
    updateExpenditure
  } from "@/api/expenditure/expenditure";
  export default {
    name: "Order",
    dicts: ['order_type'],
    data() {
      return {
        day: 0,
        total: 0,
        tableDataSale: [], // 表格数据
        tableDataOrderother: [], // 表格数据
        newRowSale: {}, // 新增的一行数据
        newRowOrderother: {}, // 新增的一行数据


        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },

        },
        // pickerOptions2: {
        //   disabledDate(time) {
        //     return time.getTime() > this.form.orderCourseEndtime;
        //   },

        // },


        num: 0,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 订单
        // 表格数据
        orderList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open_order: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderStudentName: null,
          orderCourse: null,
          orderTime: null,
          orderType: null,
          orderCourseNumber: null,
          orderFreecourseNumber: null,
          orderCourseEndtime: null,
          amountReceivable: null,
          discountAmount: null,
          actualAmountReceived: null,
          totalClassHours: null,
          consumed: null,
          residue: null,
          orderRemark: null,
          orderRemark2: null,
          orderRemark3: null,
          orderRemark4: null,
          orderRemark5: null,
          orderRemark6: null,
          orderRemark7: null,
          orderRemark8: null,
          orderRemark9: null,
          orderRemark10: null,
          moneyDetermined: null,
          moneyUnconfirmed: null,
          droppedClassesNumber: null,
          moneyDroppedTotal: null,
          otherJson: null,
          moneyOtherTotal: null,
          moneyOrderTotal: null,
          profitAndLoss: null,
          unitPrice: null,
          unit: null,
          state: null,
          saleName: null,
          deptId: null,
          studentId: null,
          saleId: null,
          // saleJson: null
        },
        // 表单参数
        form: {
          orderType: "按课时"
        },
        // 表单校验
        rules: {},
        // 学生信息表格数据
        studentList: [],
        queryParamsStudent: {},
        courseList: [],
        queryParamsCourse: {},
        queryParamsorderother: {},
        orderotherList: [],
        userList: [],
        queryParamsTeacher: {},
        expenditureList: [],
        changtype: 1,
        rules_order: {
          orderStudentName: [{
              required: true,
              message: '请输入报名学员',
              trigger: 'blur'
            },
            {
              min: 1,
              max: 5,
              message: '长度在 1 到 5 个字符',
              trigger: 'blur'
            }
          ],

          orderCourse: [{
            required: true,
            message: '请选择报名课程',
            trigger: 'change'
          }],
          orderTime: [{
            required: true,
            message: '请选择经办日期',
            trigger: 'change'
          }],
          amountReceivable: [{
            required: true,
            message: '请输入应收金额',
            trigger: 'change'
          }],


        },
      };
    },
    created() {
      // this.reset2();



    },

    watch: {
      'form.orderCourseNumber': {
        handler() {
          //购买课时数

          this.form.totalClassHours = parseInt(this.form.orderCourseNumber) + parseInt(this.form.orderFreecourseNumber);


        }
      },
      'form.orderFreecourseNumber': {
        handler() {
          //赠送课时数

          this.form.totalClassHours = parseInt(this.form.orderCourseNumber) + parseInt(this.form.orderFreecourseNumber);


        }
      },




      'form.amountReceivable': {
        handler() {
          //实收金额

          this.form.actualAmountReceived = parseInt(this.form.amountReceivable) - parseInt(this.form.discountAmount);

          if (this.form.orderType == '按课时') {
            //按课时
            this.form.unitPrice = parseInt(this.form.actualAmountReceived) / parseInt(this.form.totalClassHours);

            this.form.unitPrice = this.form.unitPrice.toFixed(2);
            // console.log( "实收变化了："+this.form.unitPrice);

            this.form.unit = "课";
          } else {
            //按时段
            this.form.unitPrice = parseInt(this.form.actualAmountReceived) / parseInt(this.day);
            this.form.unitPrice = this.form.unitPrice.toFixed(2);
            this.form.unit = "天";
          }



        }
      },
      'form.discountAmount': {
        handler() {
          //优惠
          if (this.form.discountAmount != 0) {
            this.form.actualAmountReceived = parseInt(this.form.amountReceivable) - parseInt(this.form
              .discountAmount);

          }
          if (this.form.orderType == '按课时') {
            //按课时
            this.form.unitPrice = parseInt(this.form.actualAmountReceived) / parseInt(this.form.totalClassHours);

            this.form.unitPrice = this.form.unitPrice.toFixed(2);
            // console.log( "实收变化了："+this.form.unitPrice);

            this.form.unit = "课";
          } else {
            //按时段
            this.form.unitPrice = parseInt(this.form.actualAmountReceived) / parseInt(this.day);
            this.form.unitPrice = this.form.unitPrice.toFixed(2);
            this.form.unit = "天";
          }



        }
      },
      //计算每节课多少钱或者每天多少钱
      'form.actualAmountReceived': {
        handler() {
          //实收金额
          // console.log("实收金额变化");

          // if (this.form.orderType == '按课时') {
          //   //按课时
          //   this.form.unitPrice = parseInt(this.form.actualAmountReceived) / parseInt(this.form.totalClassHours);

          //   this.form.unitPrice = this.form.unitPrice.toFixed(2);
          //   console.log( "实收变化了："+this.form.unitPrice);

          //   this.form.unit = "课";
          // } else {
          //   //按时段
          //   this.form.unitPrice = parseInt(this.form.actualAmountReceived) / parseInt(this.day);
          //   this.form.unitPrice = this.form.unitPrice.toFixed(2);
          //   this.form.unit = "天";
          // }



        }
      },


      form: {
        deep: true,
        handler() {
          // console.log('form改变了');
          // if (this.form.orderType == '按课时') {
          //   //按课时
          //   this.form.unitPrice = parseInt(this.form.actualAmountReceived) / parseInt(this.form.totalClassHours);
          //   this.form.unitPrice = this.form.unitPrice.toFixed(2);
          // } else {
          //   //按时段
          //   this.form.unitPrice = parseInt(this.form.actualAmountReceived) / parseInt(this.day);
          //   this.form.unitPrice = this.form.unitPrice.toFixed(2);
          // }
        }
      },


    },
    methods: {
      opened(){
        this.form.orderCourseEndtime = "";
        this.getStudentList();
        this.getCourseList();
        this.getListOrderother();
        this.getTeacherList();
      },
      closed() {
        console.log("关闭了");
        this.$emit('success', 'addsuccess'); // 触发名为'childEvent'的自定义事件，并传递数据
      },

      checkAllValuesNotEmpty(obj) {
        const values = Object.values(obj); // 获取对象的所有属性值

        for (let value of values) {
          if (!value || typeof value === 'undefined' || Array.isArray(value) && !value.length) {
            return false; // 如果存在任何一个值为空或未定义，则返回false
          }
        }

        return true; // 若没有发现任何值为空或未定义，则返回true
      },
      getstudentmessage(e) {
        console.log(e);
        var student = this.studentList.find(item => item.userName == e)
        // console.log(student);
        this.form.studentId = student.id;
        this.queryParamsStudent.id = student.id;
        this.queryParamsStudent.userState = "在读学员"

      },
      handlemoneyChange() {
        var that = this;
        if (this.form.actualAmountReceived != null) {
          // console.log(this.form.actualAmountReceived);
          var allCourseNumber = this.form.orderCourseNumber + this.form.orderFreecourseNumber;
          // console.log(allCourseNumber);
          if (allCourseNumber != 0) {
            that.form.unitPrice = that.form.actualAmountReceived / allCourseNumber;
            that.form.unitPrice = that.form.unitPrice.toFixed(2)
          } else {
            that.form.unitPrice = 0;
          }

        }

      },
      handleChange(type) {
        console.log(type);
        this.changtype = type;
        if (this.changtype == 1) {
          if (this.day != 0) {
            var result = calculateDaysAfter(this.form.orderTime, this.day); // 计算7天后的日期
            // console.log("7天后A是" + result.toLocaleString());
            this.form.orderCourseEndtime = result.toLocaleString();

          } else {
            this.form.orderCourseEndtime = ""
          }
        } else if (this.changtype == 2) {

          if (this.day != 0) {
            var result = calculateDaysAfter(this.form.orderTime, this.day); // 计算7天后的日期
            // console.log("7天后B是" + result.toLocaleString());
            this.form.orderCourseEndtime = result.toLocaleString();

          } else {
            this.form.orderCourseEndtime = ""
          }


        } else if (this.changtype == 3) {
          var result = calculateDaysBetween(this.form.orderTime, this.form.orderCourseEndtime);
          this.day = result;
          // this.form.orderCourseEndtime = result;
        }


      },


      getTeacherList() {
        this.queryParamsTeacher.deptId = this.$store.state.user.deptId;

        listUser2(this.queryParamsTeacher).then(response => {
          this.userList = response.rows;
          // console.log(this.userList);
          // this.total = response.total;
          // this.loading = false;
        });
      },

      getListOrderother() {

        this.queryParams.deptId = this.$store.state.user.deptId;
        listExpenditure(this.queryParams).then(response => {
          this.expenditureList = response.rows;

        });
      },

      addRow(type) {

        if (type == 1) {

          // 添加一行数据
          const newRowOrderother = {
            ID: Math.random() * 1000 + 5,
            orderother: undefined,
            orderothernumber: 1,
            orderothermoney: undefined,
          };
          this.tableDataOrderother.push(newRowOrderother);
          console.log(this.tableDataOrderother);
        } else {
          // 添加一行数据
          const newRowSale = {
            ID: Math.random() * 1000 + 5,
            user: undefined,
            usernumber: 10,

          };
          this.tableDataSale.push(newRowSale);
          console.log(this.tableDataSale);
        }


      },
      deleteRow(type, row) {
        if (type == 1) {
          // 删除行数据
          const index = this.tableDataOrderother.indexOf(row);
          if (index !== -1) {
            this.tableDataOrderother.splice(index, 1);
          }
        } else {
          const index = this.tableDataSale.indexOf(row);
          if (index !== -1) {
            this.tableDataSale.splice(index, 1);
          }
        }

      },
      /** 查询课程管理列表 */
      getCourseList() {
        this.queryParamsCourse.deptId = this.$store.state.user.deptId;
        this.queryParamsCourse.courseState = "在开课程";
        listCourse(this.queryParamsCourse).then(response => {
          this.courseList = response.rows;



        });
      },
      /** 查询学生信息列表 */
      getStudentList() {

        this.queryParamsStudent.deptId = this.$store.state.user.deptId;
        listStudent(this.queryParamsStudent).then(response => {
          this.studentList = response.rows;


        });
      },
      getStudentList2(e) {

        this.queryParamsStudent.deptId = this.$store.state.user.deptId;
        listStudent(this.queryParamsStudent).then(response => {
          this.studentList = response.rows;

          if (e != null) {
            var student = this.studentList.find(item => item.userName == e)
            console.log(student);
            this.queryParamsStudent.id = student.id;
            this.queryParamsStudent.userState = "在读学员"
            this.start(e, student.id);
          } else {
            this.start();
          }


        });
      },


      open(e) {
        this.open_order = true;
        console.log(e);
        this.getStudentList2(e);


      },

      // 取消按钮
      cancel() {
        this.open_order = false;
        this.start();
      },

      start(e, e2) {
        this.form = {
          orderType: '按课时',
          orderCourseNumber: 0,
          orderFreecourseNumber: 0,
          orderCourseEndtime: "",
          discountAmount: 0,
          studentId: e2
        };

        if (e != null) {
          this.form.orderStudentName = e;
        }

        const date = new Date(); // 创建一个表示当前时间的Date对象
        const formattedDate =
          `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
        this.form.orderTime = formattedDate;
        this.resetForm("form");
      },

      // 表单重置
      reset() {
        this.form = {
          orderId: null,
          orderStudentName: null,
          orderCourse: null,
          orderTime: null,
          orderType: null,
          orderCourseNumber: null,
          orderFreecourseNumber: null,
          orderCourseEndtime: "",
          amountReceivable: null,
          discountAmount: null,
          actualAmountReceived: null,
          totalClassHours: null,
          consumed: null,
          residue: null,
          delFlag: null,
          createTime: null,
          createBy: null,
          updateBy: null,
          updateTime: null,
          orderRemark: null,
          orderRemark2: null,
          orderRemark3: null,
          orderRemark4: null,
          orderRemark5: null,
          orderRemark6: null,
          orderRemark7: null,
          orderRemark8: null,
          orderRemark9: null,
          orderRemark10: null,
          moneyDetermined: null,
          moneyUnconfirmed: null,
          droppedClassesNumber: null,
          moneyDroppedTotal: null,
          otherJson: null,
          moneyOtherTotal: null,
          moneyOrderTotal: null,
          profitAndLoss: null,
          unitPrice: null,
          unit: null,
          state: null,
          saleName: null,
          deptId: null,
          studentId: null,
          saleId: null,
          saleJson: null
        };
        this.tableDataOrderother = [];
        this.tableDataSale = [];
        this.resetForm("form");
      },





      /** 提交按钮 */
      submitForm() {
        var that = this;
        console.log("88888");
        console.log(this.form.orderCourseEndtime);
        if (this.form.orderCourseEndtime == "") {
          this.form.orderCourseEndtime = "0"
        }

        //订单其他
        if (this.tableDataOrderother.length != 0) {
          var allothermoney = 0;

          for (var i = 0; i < this.tableDataOrderother.length; i++) {
            var boolen = that.checkAllValuesNotEmpty(that.tableDataOrderother[i]);

            if (!boolen) {
              this.$modal.msgError("请检查其他费用的值");
              return;
            }
            allothermoney = allothermoney + parseInt(that.tableDataOrderother[i].orderothermoney)
          }

          this.form.otherJson = JSON.stringify(this.tableDataOrderother);
          this.form.moneyOtherTotal = allothermoney;
        } else {
          this.form.otherJson = null;
          this.form.moneyOtherTotal = 0;
        }
        if (this.tableDataSale.length != 0) {
          //订单销售
          for (var i = 0; i < this.tableDataSale.length; i++) {
            var boolen = that.checkAllValuesNotEmpty(that.tableDataSale[i]);

            if (!boolen) {
              this.$modal.msgError("请检查订单销售的值");
              return;
            }

          }

          this.form.saleJson = JSON.stringify(this.tableDataSale);
        } else {
          this.form.saleJson = null
        }
        this.form.totalClassHours = parseInt(this.form.orderCourseNumber) + parseInt(this.form.orderFreecourseNumber);

        this.form.residue = parseInt(this.form.orderCourseNumber) + parseInt(this.form.orderFreecourseNumber);
        this.form.consumed = "0";
        this.form.state = "未开始";
        this.form.deptId = this.$store.state.user.deptId;
        this.form.moneyOrderTotal = parseInt(this.form.actualAmountReceived) + parseInt(this.form.moneyOtherTotal);
        // console.log( this.form.moneyOrderTotal);


        this.$refs["form"].validate(valid => {
          if (valid) {
            this.form.deptId = this.$store.state.user.deptId;
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功!");

              updateStudent(that.queryParamsStudent).then(response => {
                this.$emit('AddOrderSuccess', 'addordersuccess'); // 触发名为'childEvent'的自定义事件，并传递数据
              });
              this.open_order = false;


              this.reset();
            });

          } else {
            this.$modal.msgError("请输入必要数据!");
          }
        });
      },


    }
  };
</script>
